package cn.sc.summer.rabbitmq.builder;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import cn.sc.summer.constant.project.DateConstant;
import cn.sc.summer.constant.rabbit.RabbitConstant;
import cn.sc.summer.redis.util.RedisHelper;

import java.util.Date;

/**
 * 类名：构造者实现类
 *
 * @author a-xin
 * @date 2023/9/5 14:47
 */
public class RabbitBuilder extends RabbitMessageBuilder {

    private final JSONObject message = new JSONObject();

    /**
     * 构造message发布的基础信息
     */
    @Override
    protected void buildRabbitMessage() {
        String randomKey = RandomUtil.randomString(32);
        RedisHelper.zAdd(RabbitConstant.CONSUMER_KEY, randomKey, 1.0D);
        message.put(RabbitConstant.CHECK_KEY, randomKey);
        message.put(RabbitConstant.DATE_KEY, DateUtil.format(new Date(), DateConstant.YYYY_MM_DD_HH_MM_SS_1));
    }

    @Override
    protected JSONObject build() {
        return message;
    }

}
